﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// String serializer doesn't convert the bytes to/from big endian. The bytes 
    /// are left as is, since they are strings.
    /// </summary>
    public class StringSerializer : AbstractSerializer<string>
    {
        public static StringSerializer Instance = new StringSerializer();
        protected System.Text.UTF8Encoding encoding = new UTF8Encoding();

        public StringSerializer()
        {
        }
        public override ComparatorType GetComparatorType()
        {
            return ComparatorType.UTF8TYPE;
        }
        override public ComparatorType ComparatorType
        {
            get
            {
                return ComparatorType.UTF8TYPE;
            }
        }
        public override byte[] ToBytes(string obj)
        {
            return encoding.GetBytes(obj);
        }
        public override Utils.ByteBuffer ToByteBuffer(string obj)
        {
            return new Utils.ByteBuffer(encoding.GetBytes(obj));
        }
        public override string FromBytes(byte[] bytes)
        {
            return encoding.GetString(bytes);
        }
        public override string FromByteBuffer(Utils.ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
    }
}
